/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.tabpane;

import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.plaf.basic.BasicButtonUI;

/**
 * A Button with a close icon, used in the HeaderPanel to close a Tab
 * 
 * @author Pascal
 */
public class TabCloseButton extends JButton {
    
    private ImageIcon cross;
    private ImageIcon crossred;
    
    public TabCloseButton() {
        cross = new ImageIcon(getClass().getResource("/gui/resources/cross.png"));
        crossred = new ImageIcon(getClass().getResource("/gui/resources/crossred.png"));
        
        setPreferredSize(new Dimension(17, 17));
        setUI(new BasicButtonUI());
        setContentAreaFilled(false);
        setFocusable(false);
        setRolloverEnabled(true);
        setRolloverIcon(crossred);
        setIcon(cross);
        addMouseListener(new MouseAdapter() {
            
            @Override
            public void mousePressed(MouseEvent e) {
                //make sure the correct icon is set when the button is pressed
                setIcon(crossred);
            }
            
            @Override
            public void mouseReleased(MouseEvent e) {
                setIcon(cross);
            }
        });
    }
}
